package com.xqb.common.config;

import com.xqb.common.constants.MQConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: JinChen Zhu
 * @CreateTime: 2024-10-29  12:31
 */
@Configuration
public class TopicMQConfig {
    @Bean
    public TopicExchange courseTopicExchange() {
        return new TopicExchange(MQConstants.COURSE_TOPIC, true, false);
    }

    @Bean
    public Queue courseInsertQueue() {
        return new Queue(MQConstants.COURSE_INSERT_QUEUE, true);
    }

    @Bean
    public Queue courseDeleteQueue() {
        return new Queue(MQConstants.COURSE_DELETE_QUEUE, true);
    }

    @Bean
    public Binding courseInsertBinding() {
        return BindingBuilder.bind(courseInsertQueue()).to(courseTopicExchange()).with(MQConstants.COURSE_INSERT_KEY);
    }

    @Bean
    public Binding courseDeleteBinding() {
        return BindingBuilder.bind(courseDeleteQueue()).to(courseTopicExchange()).with(MQConstants.COURSE_DELETE_KEY);
    }

    @Bean
    public TopicExchange emailTopicExchange() {
        return new TopicExchange(MQConstants.EMAIL_TOPIC, true, false);
    }


    @Bean
    public Queue emailInsertQueue() {
        return new Queue(MQConstants.EMAIL_INSTITUTION_QUEUE, true);
    }

    @Bean
    public Binding emailInsertBinding() {
        return BindingBuilder.bind(emailInsertQueue()).to(emailTopicExchange()).with(MQConstants.EMAIL_INSTITUTION_KEY);
    }


}
